package Year21_Month12.day1206;

public class ThreadDemo {
    static class Counter{
        public int count = 0;
        public synchronized void incerease(){
            count++;
        }
    }
    public static void main(String[] args) throws InterruptedException{
        Counter counter = new Counter();

        Thread t1 = new Thread(){
            @Override
            public void run(){
                for (int i = 0; i < 50000; i++) {counter.incerease();}
            }
        };
        t1.start();
        Thread t2 = new Thread(){
            @Override
            public void run(){
                for (int i = 0; i < 50000; i++) {counter.incerease();}
            }
        };
        t2.start();
        t1.join();
        t2.join();
        System.out.println(counter.count);//仔细注意区别
    }
}
